<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>コントロールパネル</title>

    <link href="./assets/styles/default.css" rel="stylesheet" />
    <link href="./assets/styles/page/item_form.css" rel="stylesheet" />
	<script src="./assets/scripts/libs/jquery-1.7.1.min.js" type="text/javascript"></script>
	<script src="./assets/scripts/import.js" type="text/javascript"></script>
	
	
	<script type="text/javascript">
		$(function(){
			back_to_search();
			//categoryModal({url:"{{'Home/Category/index'|U}}?keepThis=true&parent=3&TB_iframe=true&height=500&width=300&modal=false",mode:"tree"});
			
			$('.free > p').click(function(){
				var t = $(' > div',$(this).parent());
				var h = t.height();

				if(t.is(":hidden")){
					$(this).addClass("active");
					$('em',this).text('j');
					t.css({"height":"0px"})
					.show()
					.animate({height:h+"px"},300,function(){
						$(this).css({height:""});
					});
				}else {
					$(this).removeClass("active");
					$('em',this).text('g');
					t.animate({height:"0px"},300,function(){
						t.hide().css({height:h+"px"},300)
					});
				}
			});

			$('.close > p').click();
			
			

		});
		
		
		
		$(function() {
			categoryModal({url:	"{{'Home/Category/index'|U}}?keepThis=true&parent=3&TB_iframe=true&height=500&width=300&modal=false",
				mode:"tree",container:"#selected_category",trigger:"#id_category a",hidden:'category'});
			compute();
		});
		
		function spec(){
			document.fm.category.value=document.fm.category.value.replace(",","|");
			document.fm.goods_issuedate.value=document.fm.goods_issuedate_year.value+"/"+document.fm.goods_issuedate_month.value+"/"+"01";
			document.fm.submit();
			return true;
		}

		function compute(){
			var goods_unitprice = document.getElementById("goods_unitprice").value;
			var pattern = /^\d+[.]?\d*$/;
			if(isNaN(goods_unitprice) || !pattern.test(goods_unitprice)){
					alert("半角数字で入力して下さい");
					return ;
			}
			goods_unitprice=parseFloat(goods_unitprice);
			var tv =parseInt(goods_unitprice*(1+{{$tax}}));
			$("#tax_in").text(tv);
		}

	</script>
</head>
<body>

{{$zhead}}

<div id="container">
	{{$zmenu}}

    <article>
    	<h2><span>&nbsp;</span>商品管理<p><a href="javascript:;">Open Plugins</a></p></h2>
        <nav>
        	<ul>
				<li class="active"><a href="{{'Home/Item/index'|U}}"><span>商品検索</span></a></li>
        <li><a href="{{'Home/Item/insert'|U}}"><span>商品登録</span></a></li>
        <li><a href="{{'Home/Item/rank'|U}}"><span>ランキング</span></a></li>
        <li><a href="{{'Home/Item/set'|U}}"><span>基本設定</span></a></li>
			</ul>
        </nav>
		<section id="content">
			<h3>商品更新</h3>
			
			{{if $show_massg}}
			<p class="message">商品情報を更新します。</p>
			<form name="fm" action="{{'Home/Item/update'|U}}" method="post" onsubmit="return spec();" >
				<h4><span>&nbsp;</span>基本情報</h4>
				<input type="hidden" name="method" value="update"/>
				<input type="hidden" name="id" value="{{$forms.id}}"/>
				<table class="formTable">
					<tbody>		
						<tr>
							<th class="must1">状態</th>
							<td>
						    {{html_radios name="goods_status" options=$goods_status checked=$forms.goods_status"}}{{$err_mes.goods_status}}
							</td>
						</tr>
						<tr>
							<th class="must1">商品コード</th>
							<td><input type="text" name="goods_id" class="text" value="{{$forms.goods_id}}" />{{$err_mes.goods_id}}</td>
						</tr>
						<tr>
							<th class="must1">商品名</th>
							<td><input type="text" name="goods_name" class="text" value="{{$forms.goods_name}}" />{{$err_mes.goods_name}}</td>
						</tr>
						<tr>
							<th class="must1">商品種別</th>
							<td>
							{{html_radios name="goods_type" options=$goods_type checked=$forms.goods_type"}}{{$err_mes.goods_type}}	
							</td>
						</tr>
						<tr>
							<th class="must1">カテゴリ（複数）</th>
							<td>
                            <dd>
							<p class="btn_blank float-left btn_category" id="id_category">
                                	<a href="javascript:;">カテゴリ選択</a>
                            </p>
                                <input type="hidden" name="category" value="{{$category_id}}" />
                            	<ul id="selected_category" class="float-left">
                                      {{ section name=sec1 start=0 loop=$category_data step=1 }}
											<li id="{{ $category_data[sec1].category_cd }}"><a href="javascript:;" class="delete_category">削除</a> {{$category_data[sec1].category_name}}</li>
                                      {{/section }}
                                </ul>
						</dd>
                          {{$err_mes.category_id}}</td>
						</tr>
						<tr>
							<th class="must1">本体価格</th>
							<td><input type="text" name="goods_unitprice" id="goods_unitprice" class="short" value="{{$forms.goods_unitprice}}" onkeyup="compute()"/>円（税込み<span id="tax_in">{{$forms.tax}}</span>円）{{$err_mes.goods_unitprice}}</td>
						</tr>
						<tr>
							<th class="must1">在庫</th>
							<td>
								<select name="goods_stockstatus">
									  {{html_options options=$goods_stockstatus selected=$forms.goods_stockstatus}}
								</select>
								{{$err_mes.goods_stockstatus}}
							</td>
						</tr>
						<tr>
							<th class="must1">商品画像（複数）</th>
							<td>
							<div id="img" >
							
							{{ foreach from=$formsimg key=k item=v name="member" }}
								<div id="{{$k}}" style="clear:both">
								<img width="240" src="{{$v.imgdir}}"><br>
								<a class="delete_mini" onclick="remove_img({{$k}});" 
								href="javascript:;">削除</a>
								<input type="hidden" value="{{$v.img}}" name="upload_image_name[]">
								</div>
								
						    {{ /foreach }}	
							
							</div>
							<div style="clear:both"></div>
							<input id="fileToUpload" type="file" name="goods_image" value="{{$forms.goods_image}}" onchange="return ajaxFileUpload('fileToUpload');" ></td>
						</tr>
						<tr>
							<th class="must1">発行月</th>
							<td>
							<table style="width:200px">
							<tr>
								<input type="hidden" name="goods_issuedate" >
								<td style="padding:0px;width:100px"><input type="text" name="goods_issuedate_year"  class="short" value="{{$forms.goods_issuedate_year}}" /></td>
								<td style="padding:0x;">年</td>
								<td>
								<select name="goods_issuedate_month" style="padding:0x;">
								{{html_options options=$select_month selected=$forms.goods_issuedate_month}}
								</select>
								</td>
								<td style="padding:0x;">月</td>
							</tr>
							</table>
							{{$err_mes.goods_issuedate}}</td>
						</tr>
						<tr>
							<th class="must1">仕様</th>
							<td><input type="text" name="goods_style" class="text" value="{{$forms.goods_style}}" />{{$err_mes.goods_style}}</td>
						</tr>
						<tr>
							<th class="must1">フラグ</th>
							<td>
								 {{ foreach from=$goods_mark key=kk item=vv name="member" }}
					   		     {{assign var="goods_mark" value= goods_mark$kk}}
							    <label><input type="checkbox" name="goods_mark{{$kk}}"  {{if $forms[$goods_mark] == $kk }} checked="true" {{/if}} value="{{$kk}}" />{{$vv}}</label>
						         {{ /foreach }}
							</td>
						</tr>
						<tr>
							<th class="must1">単位</th>
							<td>
								<select name="goods_unit">
									{{html_options options=$goods_unit selected=$forms.goods_unit}}
								</select>{{$err_mes.goods_unit}}
							</td>
						</tr>
						<tr>
							<th class="must1">キャッチコピー</th>
							<td><input type="text" name="goods_slogan" class="text" value="{{$forms.goods_slogan}}" />{{$err_mes.goods_slogan}}</td>
						</tr>
						<tr>
							<th>表示順</th>
							<td><input type="text" name="goods_order" value="{{$forms.goods_order}}" class="smartspinner" /></td>
						</tr>
						<tr>
							<th class="must1">META Description</th>
							<td><textarea name="metadescription">{{$forms.metadescription}}</textarea>{{$err_mes.metadescription}}</td>
						</tr>
						<tr>
							<th class="must1">META Keyword</th>
							<td><textarea name="metakeyword">{{$forms.metakeyword}}</textarea>{{$err_mes.metakeyword}}</td>
						</tr>
						<tr>
							<th>試し読みURL</th>
							<td><input type="text" name="tryURL" class="text" value="{{$forms.tryURL}}" />{{$err_mes.tryURL}}</td>
						</tr>
						<tr>
							<th>外部URL</th>
							<td><input type="text" name="outsideURL" class="text" value="{{$forms.outsideURL}}" />{{$err_mes.outsideURL}}</td>
						</tr>
						<tr>
							<th>社内コメント</th>
							<td><textarea name="insideappraise">{{$forms.insideappraise}}</textarea></td>
						</tr>
						<tr>
							<th>販売開始日時</th>
							<td><input type="text" name="sellbegin" class="text_date" value="{{$forms.sellbegin}}" /></td>
						</tr>
						<tr>
							<th>販売終了日時</th>
							<td><input type="text" name="sellend" class="text_date" value="{{$forms.sellend}}" /></td>
						</tr>
					</tbody>
				</table>

				 <div class="free">
					<p>
						<em>j</em>
						フリースペース1 
					</p>
					<div>
						<table class="formTable">
							<tbody>
								<tr>
									<td>
										<textarea name="freespace1" class="mce_edit">{{$forms.freespace1}}</textarea>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>

				 <div class="free close">
					<p>
						<em>j</em>
						フリースペース2
					</p>
					<div>
						<table class="formTable">
							<tbody>
								<tr>
									<td>
										<textarea name="freespace2" class="mce_edit">{{$forms.freespace2}}</textarea>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>

				 <div class="free close">
					<p>
						<em>j</em>
						フリースペース3
					</p>
					<div>
						<table class="formTable">
							<tbody>
								<tr>
									<td>
										<textarea name="freespace3" class="mce_edit">{{$forms.freespace3}}</textarea>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>

				<p class="button">
					<button type="submit" class="submit" ><span>更新</span></button>
				</p>
			</form>
		
		{{else}}
			<p class="message">{{$message}}</p>
			
			
			<ul class="result_btn clear" style="margin-top:20px;">
                <li><a href="{{'Home/Item/index'|U}}">一覧に戻る</a></li>
                <li><a href="{{'Home/Item/insert'|U}}">続けて新規登録する</a></li>
            {{if isset($forms.id)}}
                <li><a href="{{'Home/Item/update'|U}}?id={{$forms.id}}">登録した内容を更新する</a></li>
            {{/if}}
        	</ul>
			
		{{/if}}
		
		</section>
	</article>
</div>

<script type="text/javascript" src="./assets/scripts/plugins/ajaxfileupload.js"></script>

<script type="text/javascript">

	function ajaxFileUpload(id)
	{
		
		$.ajaxFileUpload
		(
			{
				url:'Home_Item_ajaximage.html?id={{$forms.id}}',
				secureuri:false,
				fileElementId:id,
				dataType: 'json',
				data:{id:id },
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{	
							$("#img").append('<div id='+data.id+' style="clear:both"><img src="'+data.msg+'" width="240"><br><a href="javascript:;" onclick="remove_img('+data.id+');" class="delete_mini">削除</a><input type="hidden" name="upload_image_name[]" value="'+data.pathname+'"></div>');
							$(".filename").html('No file selected');
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		return false;
	}
	
	function remove_img(id){
		$.ajax({
		 type: "POST",
		 url: "Home_Item_ajaxdeleteimage.html",
		 data: {"filename":$("#"+id+">img").attr("src")},
		 success: function(msg){ $("#"+id).remove(); } 
		});
		
		
	}
</script>
	
	
	
{{$zfooter}}
</body>
</html>